package org.tity.test.sql;

import java.io.File;
import java.io.IOException;

import org.tity.commons.environment.PathTool;
import org.tity.sql.sql.builder.SE;
import org.tity.sql.sql.builder.SQL;
import org.tity.sql.sql.parser.SQLParserUtil;

import jodd.io.FileUtil;

public class GetCountSQL {
	
	public static void main(String[] args) throws IOException {
		
		String path= PathTool.getDir(GetCountSQL.class).getAbsolutePath()+File.separator+"count-sql.txt";
		String content=FileUtil.readUTFString(path);
		 
		SQL sql=getCountSQL(new SE(content), "X");
		
		System.out.println(sql.toString());
		
	}
	
	public static SQL getCountSQL(SQL sql,String name) {
		 try {
			return SQLParserUtil.getCountSQL(sql,name);
		} catch (Exception e) {
			e.printStackTrace();
			return new SE("select count(1) "+name+" from ("+sql+") A");
		}
	}
	
	

}
